package com.itheima.bos.web.action;

import com.itheima.bos.domain.Noticebill;
import com.itheima.bos.domain.User;
import com.itheima.bos.service.INoticebillService;
import com.itheima.bos.utils.BOSContext;
import com.itheima.bos.web.action.base.BaseAction;
import com.itheima.crm.domain.Customer;
import com.itheima.crm.service.CustomerService;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.IOException;

/**
 * Created by Mr.King on 2017/3/15.
 */
@Controller
@Scope(value = "prototype")
public class NoticebillAction extends BaseAction<Noticebill> {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private INoticebillService noticebillService;

    //接收电话号码
    private String phone;
    public void setPhone(String phone) {
        this.phone = phone;
    }


    //根据电话号码查询客户
    public String findCustomerByPhone() throws IOException {
        Customer customer = customerService.findCustomerByPhone(phone);
        toJSON(customer,null);
        return NONE;
    }

    //保存业务受理单
    public String saveNoticebill() throws IOException {
        User user = BOSContext.getLoginUser();
        model.setUser(user);
        String flag = "1";
        try {
            noticebillService.save(model);
        }catch (Exception e){
            flag = "0";
        }
        ServletActionContext.getResponse().getWriter().print(flag);
        return NONE;
    }

}
